/*
 * Helstius--Basic chemistry application
 * This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 * Copyright 2012 Jaked122
 */
package org.helstius.Gui;

import java.awt.Color;

/**
 * <p>
 * Color Gradient Generator. Easy enough to work with.
 * </p>
 * <p>
 * The gradient is generated with linear interpolation(the rate of change is
 * constant across all domains).
 * </p>
 * 
 * @author Jaked122
 */
public class ColorGradient {
	int slopeg, offg;
	int slopeb, offb;
	int sloper, offr;
	int slopea, offa;

	/**
	 * <p>
	 * Initialize a new ColorGradient object beginning at the starting color,
	 * and stopping at the ending color.
	 * </p>
	 * 
	 * @param start
	 *            <p>
	 *            The color that the gradient starts at.
	 *            </p>
	 * @param end
	 *            <p>
	 *            the color that the gradient approaches at steps.
	 *            </p>
	 * @param steps
	 *            <p>
	 *            The number of subdivisions in the gradient.
	 *            </p>
	 */
	public ColorGradient(Color start, Color end, int steps) {
		slopeg = (end.getGreen() - start.getGreen()) / steps;
		slopeb = (end.getBlue() - start.getBlue()) / steps;
		sloper = (end.getRed() - start.getRed()) / steps;
		slopea = (end.getAlpha() - start.getAlpha()) / steps;
		offr = (end.getRed() - (steps * sloper));
		offb = (end.getBlue() - (steps * slopeb));
		offg = (end.getGreen() - (steps * slopeg));
		offa = (end.getAlpha() - (steps * slopea));

	}

	/**
	 * Get the color for a certain step
	 * 
	 * @param step
	 *            the integer on the path
	 * @return a similar or near appropriate transition between the various
	 *         components
	 */
	public Color getAtStep(int step) {
		Color e = new Color(offr + step * sloper, slopeg * step + offg, slopeb
				* step + offb, slopea * step + offa);
		return e;
	}

}
